package com.x.Part3_copyingAndAssignment;

/**
 * ClassName: Assignment
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2023/9/14 2:46
 */
public class Assignment {
    public static void main(String[] args) {
        int[] arr1, arr2;
        arr1 = new int[]{2,3,5,7,11,13,17,19};

        //将arr1赋值给arr2
        arr2 = arr1;
        //这里赋值赋的是地址

        //查看arr2元素值
        for (int i = 0; i < arr2.length; i++)
            System.out.print(arr2[i]+"\t");


        //改变arr2的元素值
        for(int i = 0; i < arr2.length; i++){
            if(i % 2 == 0)
                arr2[i] = i;
        }

        System.out.println();
        //发现arr1的值同样改变
        for (int i = 0; i < arr1.length; i++)
            System.out.print(arr1[i]+"\t");

        //以上操作导致arr1和arr2地址值相同，并没有创建新的数组，在堆空间中仍然只存在一个数组
        System.out.println();
        System.out.println(arr1);
        System.out.println(arr2);
    }
}
